package com.xn2001.controller;


import com.xn2001.dao.UserDao;
import com.xn2001.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * Created by 乐心湖 on 2020/4/15 17:17
 */
@RestController
@Api(tags = "用户管理相关接口")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserDao userDao;

    @GetMapping("/findAll")
    @ApiOperation("查询所有用户")
    public Collection<User> findALl(){
        return userDao.findAll();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation("根据id查询用户")
    public User findById(@PathVariable Integer id){
        return userDao.findById(id);
    }

    @PutMapping("/save")
    @ApiOperation("添加或者修改用户")
    public void save(@RequestBody User user){
        userDao.save(user);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除用户")
    public void delete(@PathVariable Integer id){
        userDao.delete(id);
    }

}
